#!/usr/bin/perl

require "./mailadmin-lib.pl";
my (%vdlist, $k, $i, $mailroot, $mntroot);

$mailroot = &qmail_dir_get();
$mntroot = &get_mnt_root();

$mailroot =~ s/^$mntroot//;

&header($text{'index_title'}, "", undef, 0, 1);

unless (&qmail_dir_check())
{
    &redirect('maildir_edit.cgi');
}

&get_vdomain_list(\%vdlist);

print "<form name=lsdform action=index.cgi method=post onsubmit='return do_submit();'>\n";
#table total virturl domain
print "<table class=mode1 width=100%>\n";

print "<tr><td valign=top width=90%>\n";

#list table of virturl domain
print "<table class=mode1 width=100% celladding=0 cellspacing=0>\n";
print "<tr class=title1><td width=40%><b>$text{'th_dname'}</b></td><td><b>$text{'th_nusers'}</b></td><td><b>$text{'th_mboxpath'}</b></td></tr>\n";
$i = 0;
my $cls;

foreach $k (sort keys %vdlist)
{
	if ($i % 2) {$cls = 'class=mode2' } else {$cls = 'class=mode1'};
	print "<tr $cls><td><input type=radio name=dname value=\"$k\"> <a href=\'list_user.cgi?dname=$k\'> $k</a></td><td>$vdlist{$k}</td><td>$mailroot</td></tr>\n";
	$i++;
}
print "</table>\n";

print "</td><td valign=top>\n";
print "<div style='valign:top;width:100%;height:300;overflow:auto'>";
print "<table>";
print "<tr><td><input class=button name=btn_add type=submit value=\'$text{'btn_adddomain'}\' onclick=\"return btn_adddomain();\"></td></tr>\n";
print "<tr><td><input class=button name=btn_del type=submit value=\'$text{'btn_deldomain'}\' onclick=\"return btn_deldomain($i);\"></td></tr>\n";

print "</table>";
print "</td></tr>\n";

print "</table>";
print "</div>";

print "</form>\n";

print <<EOF;
<script>
function do_submit()
{
    document.forms[0].btn_add.disabled = true;
    document.forms[0].btn_del.disabled = true;
}

function btn_adddomain()
{
    document.lsdform.action = "create_vdomain.cgi";
}

function btn_deldomain(length)
{
    var i;
    var find = 0;
    
    if(length < 2)
    {
	if(length < 1)
	{
	    return false;
	}
	else
	{
	    if(document.lsdform.dname.checked)
	    {
		find = 1;
	    }
	}
    }
    else
    {
	for(i = 0; i < length; i++)
	{
	    if(document.lsdform.dname[i].checked)
	    {
		find = 1;
	    }
	}
    }

    if(find == 0)
    {
	alert("$text{'msg_no_select_item'}");
	return false;
    }

    if(!confirm("$text{'msg_del_domain'}"))
    {
	return false;
    }

    document.lsdform.action = "delete_vdomain.cgi";
}
</script>
EOF


&footer("", $text{"back_mailadmin"});
